package io.mft.commons.db.mapper.proxyinvoker.invoker;

import java.lang.reflect.Method;
import java.util.List;

import cn.hutool.db.Session;
import io.mft.commons.db.ISQLParameter;
import io.mft.commons.db.mapper.BeanListMapping;
import io.mft.commons.db.mapper.BeanListMappingParser;
import io.mft.commons.db.mapper.SQLQueryMapResult;
import io.mft.commons.db.mapper.builder.ParameterWrapper;
import io.mft.commons.db.mapper.proxyinvoker.IProxyInvoker;
import io.mft.commons.function.response.kv.KVMap;
import io.mft.commons.util.CommonUtil;
public class BeanListMapperProxyInvoker implements IProxyInvoker<List<?>> {

	@Override
	public List<?> invoke(Method method, Session session, ISQLParameter sqlParameter, KVMap parameter,
			ParameterWrapper methodArgs) throws Exception{
		BeanListMapping beanListMapping=BeanListMappingParser.parse(method);
		SQLQueryMapResultProxyInvoker invoker=new SQLQueryMapResultProxyInvoker();
		SQLQueryMapResult sqlQueryMapResult=invoker.invoke(method, session, sqlParameter, parameter, methodArgs);
		List<?> list=CommonUtil.convertToObj(sqlQueryMapResult, beanListMapping.getMapperType());
		return list;
	}
}
